using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using Castle.MicroKernel.Lifestyle;

namespace NDomain.ExampleModels.BloggingSystem.Infrastructure
{
    public class PerWebRequestLifestyleManager : AbstractLifestyleManager
{
    private string PerRequestObjectID = "PerRequestLifestyleManager_" + Guid.NewGuid().ToString(); 

    public override object  Resolve(Castle.MicroKernel.CreationContext context)
{
        if(HttpContext.Current.Items[PerRequestObjectID] == null)
        {
            HttpContext.Current.Items[PerRequestObjectID] = base.Resolve(context);  // Create the actual object
        }
            
        return HttpContext.Current.Items[PerRequestObjectID];
    }
    
    public override void Dispose()
    { 
    }
}
}
